/*
 Copyright (c) 2012-2017 Open Lab
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 "Software"), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject to
 the following conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


function dateToRelative(localTime){
  var diff=new Date().getTime()-localTime;
  var ret="";

  var min=60000;
  var hour=3600000;
  var day=86400000;
  var wee=604800000;
  var mon=2629800000;
  var yea=31557600000;

  if (diff<-yea*2)
    ret ="要 ## 年".replace("##",(-diff/yea).toFixed(0));

  else if (diff<-mon*9)
    ret ="要 ## 月".replace("##",(-diff/mon).toFixed(0));

  else if (diff<-wee*5)
    ret ="要 ## 周".replace("##",(-diff/wee).toFixed(0));

  else if (diff<-day*2)
    ret ="要 ## 天".replace("##",(-diff/day).toFixed(0));

  else if (diff<-hour)
    ret ="要 ## 小时".replace("##",(-diff/hour).toFixed(0));

  else if (diff<-min*35)
    ret ="大约1个小时";

  else if (diff<-min*25)
    ret ="大约半个小时";

  else if (diff<-min*10)
    ret ="大约10分钟";

  else if (diff<-min*2)
    ret ="大约2分钟";

  else if (diff<=min)
    ret ="刚刚";

  else if (diff<=min*5)
    ret ="5分钟之前";

  else if (diff<=min*15)
    ret ="一刻钟之前";

  else if (diff<=min*35)
    ret ="半个小时之前";

  else if (diff<=min*75)
    ret ="1个小时之前";

  else if (diff<=hour*5)
    ret ="几个小时之前";

  else if (diff<=hour*24)
    ret ="## 小时之前".replace("##",(diff/hour).toFixed(0));

  else if (diff<=day*7)
    ret ="## 天之前".replace("##",(diff/day).toFixed(0));

  else if (diff<=wee*5)
    ret ="## 周之前".replace("##",(diff/wee).toFixed(0));

  else if (diff<=mon*12)
    ret ="## 个月之前".replace("##",(diff/mon).toFixed(0));

  else
    ret ="## 年之前".replace("##",(diff/yea).toFixed(0));

  return ret;
}

//override date format i18n

Date.monthNames = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
// Month abbreviations. Change this for local month names
Date.monthAbbreviations = ["一","二","三","四","五","六","七","八","九","十","十一","十二"];
// Full day names. Change this for local month names
Date.dayNames =["日期日","日期一","日期二","日期三","日期四","日期五","日期六"];
// Day abbreviations. Change this for local month names
Date.dayAbbreviations = ["日","一","二","三","四","五","六"];
// Used for parsing ambiguous dates like 1/2/2000 - default to preferring 'American' format meaning Jan 2.
// Set to false to prefer 'European' format meaning Feb 1
Date.preferAmericanFormat = false;

Date.firstDayOfWeek =0;
Date.defaultFormat = "yyyy-M-d";
Date.masks = {
  fullDate:       "EEEE, MMMM d, yyyy",
  shortTime:      "h:mm a"
};
Date.today="Today";

Number.decimalSeparator = ".";
Number.groupingSeparator = ",";
Number.minusSign = "-";
Number.currencyFormat = "###,##0.00";



var millisInWorkingDay =28800000;
var workingDaysPerWeek =5;

function isHoliday(date) {
  var friIsHoly =false;
  var satIsHoly =true;
  var sunIsHoly =true;

  var pad = function (val) {
    val = "0" + val;
    return val.substr(val.length - 2);
  };

  var holidays = "##";

  var ymd = "#" + date.getFullYear() + "_" + pad(date.getMonth() + 1) + "_" + pad(date.getDate()) + "#";
  var md = "#" + pad(date.getMonth() + 1) + "_" + pad(date.getDate()) + "#";
  var day = date.getDay();

  return  (day == 5 && friIsHoly) || (day == 6 && satIsHoly) || (day == 0 && sunIsHoly) || holidays.indexOf(ymd) > -1 || holidays.indexOf(md) > -1;
}



var i18n = {
  YES:                 "是",
  NO:                  "否",
  FLD_CONFIRM_DELETE:  "确定删除?",
  INVALID_DATA:        "输入的日期不合规范.",
  ERROR_ON_FIELD:      "字段错误",
  OUT_OF_BOUDARIES:      "超出字段限制值:",
  CLOSE_ALL_CONTAINERS:"关闭全部?",
  DO_YOU_CONFIRM:      "确定?",
  ERR_FIELD_MAX_SIZE_EXCEEDED:      "超出字段最大值",
  WEEK_SHORT:      "W.",

  FILE_TYPE_NOT_ALLOWED:"文件类型不支持.",
  FILE_UPLOAD_COMPLETED:"文件上传完成.",
  UPLOAD_MAX_SIZE_EXCEEDED:"文件过大",
  ERROR_UPLOADING:"上传出错",
  UPLOAD_ABORTED:"上传中断",
  DROP_HERE:"拖拉文件至此",

  FORM_IS_CHANGED:     "您有未保存的数据!",

  PIN_THIS_MENU: "固定此菜单",
  UNPIN_THIS_MENU: "取消固守此菜单",
  OPEN_THIS_MENU: "打开此菜单",
  CLOSE_THIS_MENU: "关闭此菜单",
  PROCEED: "已经处理?",

  PREV: "上一个",
  NEXT: "下一个",
  HINT_SKIP: "知道了，关闭该提示",

  WANT_TO_SAVE_FILTER: "保过过滤设置",
  NEW_FILTER_NAME: "新过滤器名",
  SAVE: "保存",
  DELETE: "删除",
  HINT_SKIP: "知道了，关闭该提示",

  COMBO_NO_VALUES: "没有值...?",

  FILTER_UPDATED:"过滤器已经更新.",
  FILTER_SAVED:"过滤器正确保存."

};


